#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTable.Input;
using UTable.Input.MultiTouch;

namespace UTable.Objects.Controls
{
    public class UElementMenu: UElementMenuDirectory
    {
        internal List<int> ActiveFingers = new List<int>();

        public UElementMenu(): base()
        {
            this.Height = 50;
            this.Width = 50;
            this.IsActive = true;
            MenuRoot = this;
            ParentMenuItem = null;
            this.InputReceived += new InputEventHandler(UElementMenu_InputReceived);
        }

        void UElementMenu_InputReceived(InputEventArgs args)
        {
            
        }

        internal void OnFingerDownOnMenu(int fingerId)
        {
            if (!ActiveFingers.Contains(fingerId))
            {
                UTableHelper.CaptureFinger2(this, fingerId);
                ActiveFingers.Add(fingerId);
            }
        }

        internal void OnFingerUpOnMenu(int fingerId)
        {
            if (this.ActiveFingers.Contains(fingerId))
            {
                this.ActiveFingers.Remove(fingerId);
                if (this.ActiveFingers.Count == 0)
                {
                    this.CloseSubmenu(true);
                }
            }
        }

        internal void RaiseCommandReceivedEvent(ElementMenuCommandReceivedEventArgs args)
        {
            if (CommandReceived != null)
            {
                CommandReceived(this, args);
            }
        }

        public event ElementMenuCommandReceivedEventHandler CommandReceived;
    }

    public delegate void ElementMenuCommandReceivedEventHandler(UElementMenu sender, ElementMenuCommandReceivedEventArgs args);

    public class ElementMenuCommandReceivedEventArgs
    {
        public ElementMenuCommandReceivedEventArgs(String command, UElementMenuItem source)
        {
            _command = command;
            _originalSource = source;
        }

        private string _command;
        public UElementMenuItem _originalSource;

        public String Command
        {
            get { return _command; }
        }

        public UElementMenuItem OriginalSource
        {
            get { return _originalSource; }
        }
    }        
}
